<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      v-model="dialogVisible"
      :title="`${parameter.title}`"
      width="900px"
      draggable
      destroy-on-close
      align-center
      class="deviceWorkOrderDialog"
      append-to-body
      @close="closeDialog"
    >
      <div class="flex mb-[8px] info">
        <div
          v-if="parameter.searchParam?.usingDepartmentName"
          class="mr-[30px]"
        >
          部门：{{ parameter.searchParam?.usingDepartmentName }}
        </div>
        <div v-if="parameter.searchParam?.faultMode" class="mr-[30px]">
          故障模式：{{ parameter.searchParam?.faultMode }}
        </div>

        <div v-if="parameter.searchParam?.faultPosition" class="mr-[30px]">
          故障部位：{{ parameter.searchParam?.faultPosition }}
        </div>

        <div v-if="parameter.searchParam?.faultStatus" class="mr-[30px]">
          故障状态：{{
            parameter.searchParam?.faultStatus === "1"
              ? "停机故障"
              : "非停机故障"
          }}
        </div>

        <div
          v-if="parameter.searchParam?.reportQueryStartTime"
          class="mr-[30px]"
        >
          报修时间：{{
            parameter.searchParam?.reportQueryStartTime.split(" ")[0]
          }}
          至 {{ parameter.searchParam?.reportQueryEndTime.split(" ")[0] }}
        </div>
        <div class="mr-[30px]">总计：{{ pageable.total || 0 }}条</div>
      </div>
      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        stripe
        max-height="450"
        @sort-change="onTableSortChanged"
      >
        <el-table-column
          label="设备名称"
          prop="assetName"
          min-width="150"
          show-overflow-tooltip
          sortable
        />
        <el-table-column
          label="设备编码"
          prop="assetCode"
          min-width="120"
          show-overflow-tooltip
          sortable
        />
        <el-table-column
          label="维修开始时间"
          prop="repairStartTime"
          min-width="160"
          show-overflow-tooltip
          sortable
        />
        <el-table-column
          label="维修结束时间"
          prop="repairEndTime"
          min-width="160"
          show-overflow-tooltip
          sortable
        />

        <el-table-column
          label="故障描述"
          prop="remarks"
          min-width="160"
          show-overflow-tooltip
        />

        <el-table-column
          label="故障模式"
          prop="faultMode"
          min-width="100"
          show-overflow-tooltip
        />

        <el-table-column
          label="故障现象"
          prop="faultPhenomenon"
          min-width="160"
          show-overflow-tooltip
        />

        <el-table-column
          label="故障原因"
          prop="faultReason"
          min-width="160"
          show-overflow-tooltip
        />

        <el-table-column
          label="故障处理措施"
          prop="faultHandleMeasure"
          min-width="160"
          show-overflow-tooltip
        />
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
      <!-- <template #footer>
        <div class="dialog-footer">
          <el-button color="rgb(0,119,255)" type="primary" @click="closeDialog"
            >确 定</el-button
          >
        </div>
      </template> -->
    </el-dialog>
  </div>
</template>

<script setup lang="ts" name="DeviceManageWorkOrder">
import { ref } from "vue";
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import { filterOrder } from "@/utils/commonHooks";

export interface ExcelParameterProps {
  title: string; // 标题
  searchParam?: any; // 查询参数
}

// dialog状态
const dialogVisible = ref(false);
// 父组件传过来的参数
const parameter = ref<ExcelParameterProps>({
  title: "",
  searchParam: {},
});

// 接收父组件参数
const acceptParams = (params: ExcelParameterProps) => {
  parameter.value = { ...parameter.value, ...params };
  searchParam.value = {
    ...searchParam.value,
    ...parameter.value.searchParam,
  };
  search();
  dialogVisible.value = true;
};

function closeDialog() {
  reset();
  dialogVisible.value = false;
}

// 是否需要分页
const pagination = true;

// 请求参数
const requestApi = "/eam/eamrepairorder/queryByPage";

const initParam = reactive({
  sort: {
    column: "",
    orderBy: "",
  },
});

// 初始化搜索参数数据
const searchParamInit = {
  locationId: "",
  repairStatus: "",
  repairUser: "",
  faultStatus: "",
  repairLevel: "",
  repairSource: "",
  assetCode: "",
  assetInfo: "",
  repairCode: "",
  //   reportQuerySearch: [],
  //   reportQueryStartTime: "",
  //   reportQueryEndTime: "",
  repairQuerySearch: [],
  repairQueryStartTime: "",
  repairQueryEndTime: "",
  assetKind: 1,
};

const deleteParam = {
  api: "",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

// 排序
// 监听表格排序方法
function onTableSortChanged(column: any) {
  const { prop, order } = column;
  console.log(prop, order);

  initParam.sort = {
    column: prop,
    orderBy: filterOrder(order),
  };
}

defineExpose({
  acceptParams,
});
</script>
<style lang="scss" scoped>
// :deep(.el-table--border th.el-table__cell) {
//   text-align: left !important;
//   color: #333;
//   font-weight: bold;
// }
.info {
  color: rgb(73, 80, 97);
  // font-weight: bold;
  font-size: 15px;
  font-family: DINAlt;
  // font-family: DINPro;
}
</style>
